package com.globallogic.addtoken;

import java.util.List;

import com.globallogic.draw.Rectangle;
import com.globallogic.draw.DrawContainer;
import com.globallogic.inout.Out;
import com.globallogic.token.TokenHandler;
import com.globallogic.token.TokenProcessor;

public class TokenHandlerRectangle implements TokenHandler {

	@Override
	public void execute(TokenProcessor tokenProcessor, List<String> params) {
		
		if (parceParams(params)) {

			DrawContainer.getInstance().addDrawObject(new Rectangle(width, height));
			Out.printLn("Rectangle with width " + width + "and height " + height + " has been added.");
		    
		}
			
	}
	
	private boolean parceParams(List<String> params) {

		if (params.size() < 2) {
            
			Out.printLn("Not enought parameters for creating Rectangle");
            return false;
            
		} 			
		
		try {

			width = Integer.parseInt(params.get(0));
			height = Integer.parseInt(params.get(1));
			
		    if ((width < 0) || (height < 0)) {
		    	
		    	Out.printLn("Width and height  should be positive integer values");
	            return false;
		    	
		    }
			
		    return true;
		    
		} catch (NumberFormatException e) {
			
			Out.printLn("Width and height should be integer values");
			
		}
		
		return false;
		
	}
	
	private int width;
	private int height;

}
